﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATM_Machine
{
    public static class ConsoleValidation
    {
        public static bool IsPresent(string userInput)
        {
            if (userInput == "")
            {
                ConsoleError("This is a required field. Press a key to try again.");
                return false;
            }
            return true;
        }

        public static bool IsInteger(string userInput)
        {
            try //Try to convert userInput to an integer and return true if valid. If invalid, run the catch statement
            {
                Convert.ToInt32(userInput);
                return true;
            }
            catch (Exception)
            {
                ConsoleError(userInput + " must be a number. Press a key to try again.");
                return false;
            }
        }

        private static void ConsoleError(string errorMessage)
        {
            Console.WriteLine("");
            Console.WriteLine(errorMessage);
            Console.ReadKey();
            Console.Clear();
        }

    }
}
